using UnityEngine;
using System.Collections;

public class NPCMovements : MonoBehaviour {

    public Movements[] movements = new Movements[1];
    public bool checkPosition;
    private int count;
    public bool ready;

    void Start()
    {
        count = 0;
    }

	void Update () 
    {

        if (ready)
        {
            if (count < movements.Length)
            {
                if (!gameObject.GetComponent<iTween>())
                {
                    iTween.MoveTo(gameObject, new Vector3(movements[count].point.x, movements[count].point.y, transform.position.z), movements[count].time);
                    count++;
                }
            }
            else
            {
                ready = false;
            }
        }

        if (checkPosition)
        {
            movements[count].point = new Vector2(transform.position.x,transform.position.y);
            Movements[] current = movements;
            movements = new Movements[movements.Length + 1];

            for (int i = 0; i < current.Length; i++)
            {
                movements[i] = current[i];
                count++;
            }

            checkPosition = false;
        }
	}

    void begin()
    {
        iTween.MoveTo(gameObject, new Vector3(movements[0].point.x, movements[0].point.y, transform.position.z), movements[0].time);
        count++;
        ready = true;
    }

    [System.Serializable]
    public class Movements
    {
        public Vector2 point;
        public float time;
    }
}
